/*
	StargateWW for GarrysMod10
	Copyright (C) 2008 Prefanatic

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

--################# Do some spelling and grammar checks on the words before its sent out @Prefanatic
function GM:PlayerSay(ply, text)
	self.BaseClass:PlayerSay(ply, text)
	
	for k,v in pairs(WW.Chat.Commands) do		
		if string.find( string.sub(text, 1, v.Length), v.Arg) then
			
			if v.Notify then Notify(ply, v.Command .. " has printed to your console!", 5) end
			
			RunConsoleCommand(v.Arg)
			
			return ""
		end
	end
	
	local RetText = SpellCheck( text )
	
	local newtext = string.sub(text, 1, 2)
	local nexttext = string.sub(text, 3, string.len(text))
	local aftertext = string.Replace(newtext, "//", "(WW)") .. nexttext
	
	if string.find(newtext, "//") then
		local temptext = string.Replace(string.sub(RetText, 1, 2), "//", "") .. string.sub(RetText, 3, string.len(RetText))
		TalkToTeam(ply, temptext)
		return ""
	else
		return RetText
	end
end
		